package com.ort.ezcalendar.notificaciones;

import com.ort.ezcalendar.InfoEventoActivity;
import com.ort.ezcalendar.R;
import com.ort.ezcalendar.persistance.EventHelper;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.widget.Toast;

public class RecibirAlarma extends BroadcastReceiver {

	@Override
	public void onReceive(Context arg0, Intent arg1) {
		long id = arg1.getExtras().getLong("id_evento");
		String titulo = arg1.getExtras().getString("nombre");
		NotificationManager nm = (NotificationManager) arg0
				.getSystemService(arg0.NOTIFICATION_SERVICE);

		//
		// Create your notification
		int icon = R.drawable.ic_launcher;
		CharSequence tickerText = titulo;
		long when = System.currentTimeMillis();

		Notification notification = new Notification(icon, tickerText, when);

		Context context = arg0;
		CharSequence contentTitle = titulo;
		CharSequence contentText = arg1.getExtras().getString("lugar");
		Intent notificationIntent = new Intent(arg0, InfoEventoActivity.class);
		notificationIntent.putExtra("id", id);
		PendingIntent contentIntent = PendingIntent.getActivity(arg0, 0,
				notificationIntent, 0);

		notification.setLatestEventInfo(context, contentTitle, contentText,
				contentIntent);

		//
		// Send the notification
		notification.flags |= Notification.FLAG_AUTO_CANCEL;
		notification.defaults |= Notification.DEFAULT_SOUND;
		nm.notify(123, notification);

	}
}
